import SafeCall from "./SafeCall";

export default (function () {
    const funcMap = {}
    let now = 0
    let query = null

    return function DebounceCall(func, timeout, payload) {
        console.log(payload)

        if (func == null) return

        now = +new Date()
        query = funcMap[func + timeout + payload]

        if (query != null && now > query) query = null

        if (query == null) {
            SafeCall(func, payload)
            funcMap[func + timeout + payload] = now + timeout
        }
    }
})()


